package com.qianchang.microfinance.view.hsmywallet;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qianchang.microfinance.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 电脑 on 2018/1/16.
 */

public class HSBuyGoldAdapter extends BaseAdapter{

    private Context mContext;
    private LayoutInflater inflater;
    private List<String> listStr = new ArrayList<>();
    private int index = -1;


    public HSBuyGoldAdapter(Context context){
        this.mContext = context;
        inflater = LayoutInflater.from(context);
        listStr.add("1000元");
        listStr.add("2000元");
        listStr.add("5000元");
        listStr.add("10000元");
    }

    public void setIndex(int index){
        this.index = index;
        notifyDataSetChanged();
    }



    @Override
    public int getCount() {
        if(listStr != null && listStr.size() > 0){
            return listStr.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return listStr.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @SuppressLint("NewApi")
    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {

        Holder holder = null;
        if(view == null){
            holder = new Holder();
            view = inflater.inflate(R.layout.item_buygold_layout,null);
            holder.balance = (TextView) view.findViewById(R.id.money_text_id);
            view.setTag(holder);
        }else{
            holder = (Holder) view.getTag();
        }

        if(index == position){
            view.setBackgroundResource(R.drawable.shape_blue_stroke_bg);
            holder.balance.setTextColor(mContext.getResources().getColor(R.color.white));
        }else{
            view.setBackgroundResource(R.drawable.shape_grad_stroke_bg);
            holder.balance.setTextColor(mContext.getResources().getColor(R.color.color_2c2c2c));
        }

        holder.balance.setText(listStr.get(position));

        return view;
    }

    private class Holder{
        private TextView balance;

    }


}
